import 'package:get_storage/get_storage.dart';

class AppStorage {
  factory AppStorage() => _instance;
  static final AppStorage _instance = AppStorage._init();

  AppStorage._init();

  // 只执行一次初始化, 但是调用read获取到的值都为null？
  // Storage._init() {
  //   GetStorage.init();
  //   storage = GetStorage('box');
  //   debugPrint('storage init !!!');
  // }

  init() async {
    await GetStorage.init();
    storage = GetStorage();
  }

  late final GetStorage storage;

  dynamic read(String key) {  // key无值时为null
    return storage.read(key);
  }

  write(String key, dynamic value) {
    storage.write(key, value);
  }

  remove(String key) {
    storage.remove(key);
  }

  static const String FirstOpen = "isFirstOpen";
  // static const String Token = "token";
  static const String UserInfo = "userInfo";

}